/* Preferences.java
 *
 * Copyright 2011 Aleksey Konovalov
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 * 
 */

package org.jimm.service;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.preference.PreferenceManager;

public final class Preferences implements OnSharedPreferenceChangeListener {
	
	public static final String PREF_SOUND = "sound";
	public static final String PREF_VIBRO = "vibro";
	public static final String PREF_HIDE_OFFLINE_CONTACTS = "hideOfflineContacts";
	public static final String PREF_CUT_XSTATUS = "cut_xstatus";
	public static final String PREF_SEND_ENTER = "sendEnter";
	public static final String PREF_SEND_BUTTON_HIDE = "sendButtonHide";
	public static final String PREF_SMILE_BUTTON_HIDE = "smileButtonHide";
	public static final String PREF_LICENSE = "License";
	public static final String PREF_LANG = "lang";
	public static final String PREF_SMILE_SPACE = "smileSpace";
	public static final String PREF_CAM_ACT = "camAct";

	public static boolean soundEnabled;
	public static boolean vibroEnabled;
	public static boolean sendEnter;
	public static boolean sendButtonHide;
	public static boolean smileButtonHide;
	public static boolean license;
	public static boolean smileSpaceEnabled;
	public static int camAct;
	public static String lang;
	
	public Preferences(Context context) {
		SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
		preferences.registerOnSharedPreferenceChangeListener(this);
		readPreferences(preferences);
	}
	
	private void readPreferences(SharedPreferences preferences) {
		soundEnabled = preferences.getBoolean(PREF_SOUND, true);
		vibroEnabled = preferences.getBoolean(PREF_VIBRO, true);
		license = preferences.getBoolean(PREF_LICENSE, false);
		sendEnter = preferences.getBoolean(PREF_SEND_ENTER, false);
		sendButtonHide = preferences.getBoolean(PREF_SEND_BUTTON_HIDE, false);
		smileButtonHide = preferences.getBoolean(PREF_SMILE_BUTTON_HIDE, false);
		lang = preferences.getString(PREF_LANG, "Default");
		smileSpaceEnabled = preferences.getBoolean(PREF_SMILE_SPACE, true);
		camAct = preferences.getInt(PREF_CAM_ACT, 0);
	}

	@Override
	public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
		if (key.equals(PREF_SOUND))
			soundEnabled = prefs.getBoolean(PREF_SOUND, true);
		else if (key.equals(PREF_VIBRO))
			vibroEnabled = prefs.getBoolean(PREF_VIBRO, true);
		else if (key.equals(PREF_LICENSE))
			license = prefs.getBoolean(PREF_LICENSE, false);
		else if (key.equals(PREF_SMILE_SPACE))
			smileSpaceEnabled = prefs.getBoolean(PREF_SMILE_SPACE, true);
		else if (key.equals(PREF_SEND_ENTER))
			sendEnter = prefs.getBoolean(PREF_SEND_ENTER, false);
		else if (key.equals(PREF_SEND_BUTTON_HIDE))
			sendButtonHide = prefs.getBoolean(PREF_SEND_BUTTON_HIDE, false);
		else if (key.equals(PREF_SMILE_BUTTON_HIDE))
			smileButtonHide = prefs.getBoolean(PREF_SMILE_BUTTON_HIDE, false);
		else if (key.equals(PREF_CAM_ACT))
			camAct = prefs.getInt(PREF_CAM_ACT, 0);
	}
	
	
	
	public final boolean vibroEnabled() {
		return vibroEnabled;
	}
	
	public final boolean soundEnabled() {
		return soundEnabled;
	}
}